package io.renren.modules.echarts.controller;

import io.renren.common.utils.R;
import io.renren.modules.echarts.entity.AttendanceDate;
import io.renren.modules.echarts.entity.EchartsDate;
import io.renren.modules.echarts.entity.TeacherAttendancePie;
import io.renren.modules.echarts.entity.TeacherEvaltionPieEntity;
import io.renren.modules.echarts.service.TeacherEvaluationChartsService;
import io.renren.modules.echarts.service.TeacherPortraitService;
import io.renren.modules.jxgk.common.ZTreeNode;
import io.renren.modules.jxgk.service.TeacherInfoService;
import io.renren.modules.jxgkphone.entity.TeacherInfo;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/TeacherPortrait")
public class TeacherPortraitController {

    @Autowired
    TeacherPortraitService teacherPortraitService;
    @Autowired
    TeacherEvaluationChartsService teacherEvaluationChartsService;
    @Autowired
    TeacherInfoService teacherInfoService;

    @RequestMapping("getTeacherEvaltionEcharts")
    public R getTeacherEvaltionPie(@RequestParam Map<String, Object> params){
//        //用户名
//        String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
//        params.put("teacherId",username);
        //评教饼状图
//        List<TeacherEvaltionPieEntity> dataPie=teacherEvaluationChartsService.getTeacherEvaltionPie(params);
//        //评教柱状图，分类别
//        List<EchartsDate> dataBar=teacherEvaluationChartsService.getTeacherEvaltionBar(params);
        //相符率
        List<TeacherEvaltionPieEntity>  dataRate=teacherEvaluationChartsService.getiMatchContentRate(params);
        //分科目相符率
        List<EchartsDate> rateBar=teacherEvaluationChartsService.getTeacherEvaltionRateBar(params);
        //授课时长纵向比
        Map<String,List> timeLine=teacherPortraitService.getTimeLine(params);
        //出勤情况
        List<AttendanceDate> teacherAttendancePie=teacherPortraitService.getTeacherAttendancePie(params);
        //出勤情况纵向比
        Map<String,Object> teacherAttendanceTimePie =teacherPortraitService.getTecaherAttendanceCollegeHorizontalComparison(params);

        return R.ok().put("dataRate",dataRate).put("rateBar",rateBar).put("timeLine",timeLine).put("teacherAttendancePie",teacherAttendancePie).put("teacherAttendanceTimePie",teacherAttendanceTimePie);
    }

    @RequestMapping("getMyTeacherEvaltionEcharts")
    public R getMyTeacherEvaltionEcharts(@RequestParam Map<String, Object> params){
        //用户名
        String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
        params.put("teacherId",username);
        //评教饼状图
//        List<TeacherEvaltionPieEntity> dataPie=teacherEvaluationChartsService.getTeacherEvaltionPie(params);
//        //评教柱状图，分类别
//        List<EchartsDate> dataBar=teacherEvaluationChartsService.getTeacherEvaltionBar(params);
        //相符率
        List<TeacherEvaltionPieEntity>  dataRate=teacherEvaluationChartsService.getiMatchContentRate(params);
        //分科目相符率
        List<EchartsDate> rateBar=teacherEvaluationChartsService.getTeacherEvaltionRateBar(params);
        //授课时长纵向比
        Map<String,List> timeLine=teacherPortraitService.getTimeLine(params);
        //出勤情况
        List<AttendanceDate> teacherAttendancePie=teacherPortraitService.getTeacherAttendancePie(params);
        //出勤情况纵向比
        Map<String,Object> teacherAttendanceTimePie =teacherPortraitService.getTecaherAttendanceCollegeHorizontalComparison(params);

        return R.ok().put("dataRate",dataRate).put("rateBar",rateBar).put("timeLine",timeLine).put("teacherAttendancePie",teacherAttendancePie).put("teacherAttendanceTimePie",teacherAttendanceTimePie);
    }


    @RequestMapping("/getTeacherDataEcharts")
    public R getTeacherDataEcharts(@RequestParam Map<String, Object> params) {

        Map<String,Object> map =teacherPortraitService.getTeacherAttendanceOfCollege(params);
        return R.ok().put("r",map);
    }

    @RequestMapping("/getTecaherAttendanceCollegeHorizontalComparison")
    public R getTecaherAttendanceCollegeHorizontalComparison(@RequestParam Map<String, Object> params) {

        Map<String,Object> map =teacherPortraitService.getTecaherAttendanceCollegeHorizontalComparison(params);
        return R.ok().put("r",map);
    }

    @RequestMapping("/getTecaherAttendanceCollegeHorizontalComparisonForCollege")
    public R getTecaherAttendanceCollegeHorizontalComparisonForCollege(@RequestParam Map<String, Object> params) {
        String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
        String college=teacherInfoService.getCollegeByUsername(username);
        params.put("collegeName",college);
        Map<String,Object> map =teacherPortraitService.getTecaherAttendanceCollegeHorizontalComparison(params);
        return R.ok().put("r",map);
    }


    @RequestMapping("/getTeacherTree")
    public R getTeacherTree(@RequestParam Map<String, Object> params) {

        List<ZTreeNode> list = teacherPortraitService.getTeacherTree();
        return R.ok().put("list",list);
    }


}
